package com.ethink.system.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.ethink.system.api.info.SystemFileInfo;
import com.ethink.system.api.request.SystemFileAddRequest;
import com.ethink.system.common.entity.SystemFile;
import com.ethink.system.common.mapper.SystemFileMapper;
import com.ethink.system.converter.SystemFileConverter;
import com.ethink.system.service.SystemFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统文件表 Service接口实现
 *
 * @author default
 * @date 2022-12-01
 */
@Slf4j
@Service
public class SystemFileServiceImpl implements SystemFileService {

    @Autowired
    private SystemFileMapper systemFileMapper;

    @Autowired
    private SystemFileConverter systemFileConverter;

    @Override
    public Integer addSystemFile(SystemFileAddRequest request) {
        SystemFile systemFile = new SystemFile();
        BeanUtils.copyProperties(request, systemFile);
        return systemFileMapper.insert(systemFile);
    }

    @Override
    public Map<String, SystemFileInfo> selectMapByFileIds(List<String> fileIdList) {
        if (CollUtil.isEmpty(fileIdList)) {
            return null;
        }
        List<SystemFileInfo> systemFileInfoList = systemFileMapper.selectListByFileIds(fileIdList);
        Map<String, SystemFileInfo> map = new HashMap<>(8);
        for (SystemFileInfo systemFileInfo : systemFileInfoList) {
            map.put(systemFileInfo.getFileId(), systemFileInfo);
        }
        return map;
    }
}
